package com.lkd.controller;

import com.lkd.dto.UserDto;
import com.lkd.entity.User;
import com.lkd.service.IUserService;
import com.lkd.vo.PageBean;
import com.lkd.vo.UserVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/user-service/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("search")
    public PageBean<UserVo> search(UserDto userDto){
        return userService.search(userDto);
    }

    @PostMapping
    public void add(@RequestBody User user){
        userService.save(user);
    }

    @PutMapping
    public void update(@RequestBody User user){
        userService.updateById(user);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id){
        userService.removeById(id);
    }

}
